﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using XcoAppSpaces.Contracts.Transport;
using System.Diagnostics;
using XcoAppSpaces.Serialization.Json;

namespace test.XcoAppSpaces.Transport.Sockets
{
    class ReceivedTmp
    {
        public Stopwatch StopWatch { get; set; }
   
        public int Counter
        { get { return counter; }
        }
        public ReceivedTmp()
        {
            StopWatch = new Stopwatch();
        }
		private XcoJsonSerializer ser1 = new XcoJsonSerializer();
        private int counter = 0;
        public void MessageReceived(XcoMessage msg, string remoteAddress, IXcoTransportService commService)
        {

            IntMsg n = (IntMsg)ser1.Deserialize(msg.Content);
            Interlocked.Increment(ref counter);
           
            if (n.value % 10000 == 0)
                Console.WriteLine("{0} @ {1} millisec", n.value, StopWatch.ElapsedMilliseconds);

        }
    }

    [Serializable]
    public class IntMsg
    {
        //public string RemoteAddress { get; set; }
        public int value;
        public string strValue1;
        public string strValue2;
        public List<MsgPart> msgPartList;
    }

    [Serializable]
    public class MsgPart
    {
        public string strValue;
        public Exception exValue;
    }
}
